import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _map from "lodash/map";

/**
 * index
 * @description
 * @date 2018/10/10
 */

/* eslint-disable class-methods-use-this */
import React from 'react';
import { templates } from "../utils";
import DragComponent from "./DragComponent";
import DragField from "./DragField";

var LeftComponent = /*#__PURE__*/function (_React$Component) {
  _inherits(LeftComponent, _React$Component);

  var _super = _createSuper(LeftComponent);

  function LeftComponent(props) {
    var _this;

    _classCallCheck(this, LeftComponent);

    _this = _super.call(this, props);
    _this.renderComponents = _this.renderComponents.bind(_assertThisInitialized(_this)); // this.renderContainers = this.renderContainers.bind(this);

    return _this;
  }

  _createClass(LeftComponent, [{
    key: "render",
    value: function render() {
      return /*#__PURE__*/React.createElement("div", {
        className: "pick-box-panel-container"
      }, this.renderComponents());
    }
  }, {
    key: "renderComponents",
    value: function renderComponents() {
      var activeComponentCode = this.props.activeComponentCode;
      var template = templates[activeComponentCode];

      if (template) {
        switch (template.templateType) {
          case 'DynamicTabs':
          case 'DynamicModal':
            return this.renderTemplates(template.accepts);

          default:
            return this.renderFields(template.accepts);
        }
      }

      return this.renderTemplates(templates);
    }
  }, {
    key: "renderTemplates",
    value: function renderTemplates(acceptTemplates) {
      return _map(acceptTemplates, function (component, componentCode) {
        return /*#__PURE__*/React.createElement(DragComponent, {
          component: component,
          key: componentCode
        });
      });
    }
  }, {
    key: "renderFields",
    value: function renderFields(acceptFields) {
      return _map(acceptFields, function (component, componentCode) {
        return /*#__PURE__*/React.createElement(DragField, {
          component: component,
          key: componentCode
        });
      });
    }
  }]);

  return LeftComponent;
}(React.Component);

export { LeftComponent as default };